﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting;
using MessageBase;
using MessageCommon;

namespace MessageServer
{
    public partial class FormServer : Form
    {
        TcpChannel channel;

        public FormServer()
        {
            InitializeComponent();
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            if (channel == null)
            {
                channel = new TcpChannel(8080);
                ChannelServices.RegisterChannel(channel, false);
                RemotingConfiguration.Configure(GlobalConst.SERVER_CONFIG,false);
                //RemotingConfiguration.RegisterWellKnownServiceType(typeof(MessageObject),
                //    "CPOEMessage", WellKnownObjectMode.Singleton);

                lblStatus.Text = "Running...";
                btnStart.Enabled = false;
                btnStop.Enabled = true;
            }
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            if (channel != null)
            {
                ChannelServices.UnregisterChannel(channel);
                channel = null;
                lblStatus.Text = "Stopped.";
                btnStart.Enabled = true;
                btnStop.Enabled = false;
            }
        }
    }
}
